package com.panshi.admin_manage.controller;

import com.panshi.admin_manage.service.IRoleService;
import com.panshi.vo.DataResult;
import com.panshi.vo.SysRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping(produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class RoleController {

    @Autowired
    private IRoleService roleService;

    @GetMapping("/role-app/list")
    public DataResult find(){
        DataResult dataResult = new DataResult();
        dataResult.setData(roleService.list(null));
        return dataResult;
    }

    @PostMapping("/role-app/add")
    public Boolean add(@RequestBody SysRole sysRole){
       return roleService.save(sysRole);
    }

    @GetMapping("/role-app/del/{id}")
    public Boolean del(@PathVariable Integer id){
        SysRole sysRole = new SysRole();
        sysRole.setId(id);
        sysRole.setRStatus(-1);
        return roleService.save(sysRole);
    }

    @GetMapping("/role-app/byid/{id}")
    public DataResult fidnRoleById(@PathVariable Integer id){
        DataResult dataResult = new DataResult();
        dataResult.setData(roleService.getById(id));
        return dataResult;
    }

    @PostMapping("/role-app/upd")
    public Boolean upd(@RequestBody SysRole sysRole){
        return roleService.updateById(sysRole);
    }


}
